package d0323;

public class Course2 {
    private String title;
    private int price;

    public Course2(String title, int price) {
        this.title = title;
        this.price = price;
    }
    @Override
    public boolean equals(Object obj){
        if(this==obj){//    地址相同
            return true;
        }
        if(obj==null){
            return false;
        }
        Course2 course2=(Course2) obj;
        if(this.price!=course2.price){
            return false;
        }
        if(title==null){
            if(course2.title!=null){
                return false;
            }
        }else if(!title.equals(course2.title)){
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Course2 c1=new Course2("math",100);
        Course2 c2=new Course2("math",100);
        System.out.println(c1==c2);//比较两个对象的虚地址，false
        System.out.println(c1.equals(c2));//比较两个对象的虚地址，false
    }
}
